package com.dish.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class DAOFactory {
	
	private static String className = null;
	private static Properties prop = null; 
	
	private DAOFactory(){
		
	}
	
	static{  //静态代码块，类加载时执行，只执行一次
		//读配置文件
		InputStream in = DAOFactory.class.getClassLoader().
				getResourceAsStream("daoconfig.properties");
		prop = new Properties();
		try {
			prop.load(in);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static Object newInstance(String iname){		
		try {
			className = prop.getProperty(iname);
			return Class.forName(className).newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return null;
	}
}
